﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.ParallelArrays;
using FPA = Microsoft.ParallelArrays.FloatParallelArray;
using BPA = Microsoft.ParallelArrays.BoolParallelArray;
using IPA = Microsoft.ParallelArrays.IntParallelArray;
using PA = Microsoft.ParallelArrays.ParallelArrays;

namespace ParallelMath
{
    public class ParMath
    {
        private static ParMath instance = null;
        public static ParMath Instance
        {
            get
            {
                if(instance == null)
                    instance = new ParMath();
                return instance;
            }
        }
        public Target evalTarget;
        private  ParMath()
        {
            try
            {
                evalTarget = new DX9Target();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

        }
        public float sum(float[,] values)
        {
            
            float[] sum = new float[1];
            evalTarget.ToArray(PA.Sum(new FPA(values)),out sum);
            return sum[0];
        }

        public float[,] mmul(float[,] a, float[,] b)
        {

            float[,] result = new float[a.GetLength(0),a.GetLength(1)];

         
            evalTarget.ToArray(PA.InnerProduct(new FPA(a), new FPA(b)), out result);
            return result;
        }
    }
}
